home *** CD-ROM | disk | FTP | other *** search
- Path: nyssa.swt.edu!LN16674
- From: ln16674@nyssa.swt.edu (Leland Newsom)
- Newsgroups: comp.lang.c
- Subject: reversing a string
- Date: 10 Apr 1996 23:31:15 GMT
- Organization: Southwest Texas State University
- Message-ID: <4khgc3$gsu@central.server.swt.edu>
- Reply-To: ln16674@nyssa.swt.edu
- NNTP-Posting-Host: nyssa.swt.edu
-
-
- #include <stdio.h>
-
- static void reverse(char *str);
-
- int main(int argc, char *argv[])
-
- {
- if (argc >= 2)
- reverse(argv[1]);
-
- printf("'%s'\n", argv[1]);
-
- return 0;
- }
-
- static void reverse(char *str)
-
- {
- if (str[0] != '\0' && str[1] != '\0') {
- reverse(str+1);
- reverse(str+2);
- str[0] ^= str[1], str[1] ^= str[0], str[0] ^= str[1];
- reverse(str+1);
- }
- }
-
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-